package xm.view.item
{
	import flash.events.MouseEvent;
	
	import xm.core.XMSprite;
	
	/**
	 * <br> 클래스 설명 : </br>
	 * @author 김정환
	 */	
	public class ViewListItemRenderer extends XMSprite
	{
		
		//-----------------------------------------------------------------------------------
		// public vars
		//-----------------------------------------------------------------------------------
		
		/**
		 * List 에 정의된 gapBetweenItem 
		 */		
		public var gapBetweenItem : Number = 0;
		
		//-----------------------------------------------------------------------------------
		// protected / internal vars
		//-----------------------------------------------------------------------------------
		
		
		/**
		 * List 에서 사용할 data : Object
		 */		
		protected var data : Object;
		
		
		
		//-----------------------------------------------------------------------------------
		// private vars
		//-----------------------------------------------------------------------------------
		
		
		private var _isMove : Boolean = false;
		
		//-----------------------------------------------------------------------------------
		// public functions
		//-----------------------------------------------------------------------------------
		
		/**
		 * constructor 
		 */	
		public function ViewListItemRenderer()
		{
			super();
			
		}
		
		
		/**
		 * @param _data
		 */		
		public function set dataProvider( _data : Object ):void
		{
			data = _data;
			apply();
		}
		
		/**
		 * data : Object
		 */		
		public function get dataProvider():Object
		{
			return data;
		}
		
		
		/**
		 * apply - data 를 화면에 반영하는 과정.
		 */		
		public function apply():void
		{
			_isMove = true;
		}
		
		/**
		 * commitProperties
		 */		
		override public function commitProperties():void
		{
			super.commitProperties();
		}
		
		
		/**
		 * <br>ex )</br>
		 * <br>  - af.addSimpleItem( item, [0,0,0,0] ); // 패딩은 상,우,하,좌 순서임. 기본값은 null </br>
		 * <br>  - af.addSimpleBox( new AlignHBox().addSimpleItem( item, [0,0,0,0] ) );</br>
		 * <br>  - af 를 작동하기 위해서는 최후 af.workingAlign(); 를 호출해 주어야 한다.</br>
		 * updateDisplayList
		 */		
		override public function updateDisplayList( enforce : Boolean = false ):void
		{
			super.updateDisplayList(enforce);
		}
		
		
		
		//-----------------------------------------------------------------------------------
		// life cycle functions
		//-----------------------------------------------------------------------------------
		
		
		/**
		 * createChildren
		 */		
		override public function createChildren():void
		{
			super.createChildren();
			
			this.addEventListener(MouseEvent.MOUSE_DOWN, onInnerDownCheck );
			this.addEventListener(MouseEvent.CLICK, onInnerClickCheck )
			
		}
			
		
		/**
		 * createComplete
		 */		
		override public function creationComplete():void
		{
			super.creationComplete();
		}
		
		
		/**
		 * destroy
		 */		
		override public function destroy():void
		{
			
			this.removeEventListener(MouseEvent.MOUSE_DOWN, onInnerDownCheck );
			this.removeEventListener(MouseEvent.CLICK, onInnerClickCheck )
				
			gapBetweenItem = NaN;
			data = null;
			
				
			super.destroy();
		}
		
		
		//-----------------------------------------------------------------------------------
		// setter / getter
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		// protected functions
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		// internal functions
		//-----------------------------------------------------------------------------------
		
		
		
		
		//-----------------------------------------------------------------------------------
		// private functions
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		// event handler
		//-----------------------------------------------------------------------------------
		
		
		
		/**
		 * 만약 움직임이 있다면 클릭 이벤트를 막는다.
		 * <br />
		 * @param e
		 */		
		protected function onInnerClickCheck(e:MouseEvent):void
		{
			if( _isMove ) e.stopImmediatePropagation();
		}
		
		/**
		 * 움직임을 기본으로 false 로 하고,
		 * <br />
		 * @param e
		 */		
		protected function onInnerDownCheck(e:MouseEvent):void
		{
			_isMove = false;
		}	
		
		
		
		
		
	}
}